// #include "../include/setDataModel.h"
#include "setDataModel.h"

SetDataModel::SetDataModel() {
    initCommandMap();
}
SetDataModel::~SetDataModel() {

}

std::string SetDataModel::executeCommand(const std::string& command, std::istringstream& iss)
{
    if(commandMap.count(command)){
        std::cout << "Executing command: " << command << " ";
        return commandMap[command](iss);
    }
    return "error Set " + command + " not found";
}

void SetDataModel::initCommandMap()
{
    commandMap["sadd"] = [this](std::istringstream& iss) -> std::string {
        int count = 0;
        std::string value;
        while (iss >> value) {
            if (setDataModel.find(value) != setDataModel.end()) {
                continue;
            }
            setDataModel.insert(value);
            count++;
        }
        return "(integer) " + std::to_string(count);
    };
    commandMap["smembers"] = [this](std::istringstream& iss) -> std::string {
        std::string result{""};
        for (const auto& value : setDataModel){
            result += value + " ";
        }
        return result;
    };
}
